// Desc: 公共方法
import * as XLSX from "xlsx";

export const defaultMockMenu = [
    {
        code: 'Banner',
        name: 'Banner',
    },
    {
        code: 'Lawyer',
        name: 'Lawyer',
    },
    {
        code: 'LawyerPractice',
        name: 'LawyerPractice',
    },
    {
        code: 'LawyerFun',
        name: 'LawyerFun',
    },
    {
        code: 'LegalHubDetail',
        name: 'LegalHubDetail',
    },
    {
        name: 'User',
        code: 'user-management',
        icon: 'img_3',
        activeIcon: 'img_3_active',
        children: [
            {
                name: 'Role',
                code: 'role',
            },
            {
                name: 'User',
                code: 'user',
            }
        ]
    },
]

export const exportToExcel = (name,data = []) => {
    if (!name) {
        name = '导出文件'
    }
    if (!data) return
    // 创建一个工作簿
    const workbook = XLSX.utils.book_new();
    // 创建一个工作表
    const worksheet = XLSX.utils.aoa_to_sheet([
        ...data
    ]);

    // 将工作表添加到工作簿
    XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');

    // 生成Excel文件
    XLSX.writeFile(workbook, name + '.xlsx');
};
